package com.bdq.content.application.service;

import com.bdq.common.entity.common.CommonResult;
import com.bdq.common.exception.ServerException;
import com.bdq.common.feign.interaction.InteractionFeign;
import com.bdq.common.feign.interaction.param.InteractionDataGetParam;
import com.bdq.common.feign.interaction.param.InteractionNumInitParam;
import com.bdq.common.feign.interaction.param.VoteInitParam;
import com.bdq.common.feign.interaction.vo.InteractionDataGetVO;
import com.bdq.common.feign.interaction.vo.InteractionDataListVO;
import com.bdq.common.feign.user.UserFeign;
import com.bdq.common.feign.user.param.UserGetParam;
import com.bdq.common.feign.user.vo.UserFollowVO;
import com.bdq.common.feign.user.vo.UserGetVO;
import com.bdq.common.feign.user.vo.UserListVO;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author malei
 * @date 2024-05-15 18:29
 */
@Component
public class MyFeignClient {

    @Resource
    private InteractionFeign interactionFeign;

    @Resource
    private UserFeign userFeign;

    public Boolean interactionNumInit(InteractionNumInitParam param){
        CommonResult<Boolean> result = interactionFeign.interactionNumInit(param);
        if (result.isError()) {
            throw new ServerException("[交互服务异常]异常信息:".concat(result.getMsg()));
        }
        return result.getData();
    }

    public Boolean voteInit(VoteInitParam param) {
        CommonResult<Boolean> result = interactionFeign.voteInit(param);
        if (result.isError()) {
            throw new ServerException("[交互服务异常]异常信息:".concat(result.getMsg()));
        }
        return result.getData();
    }

    public InteractionDataGetVO getData(InteractionDataGetParam param) {
        CommonResult<InteractionDataGetVO> result = interactionFeign.getData(param);
        if (result.isError()) {
            throw new ServerException("[交互服务异常]异常信息:".concat(result.getMsg()));
        }
        return result.getData();
    }

    public UserGetVO getUser(UserGetParam param) {
        CommonResult<UserGetVO> result = userFeign.getUser(param);
        if (result.isError()) {
            throw new ServerException("[用户服务异常]异常信息:".concat(result.getMsg()));
        }
        return result.getData();
    }

    public List<InteractionDataListVO> listData(Long userId, List<Long> contentIds) {
        CommonResult<List<InteractionDataListVO>> result = interactionFeign.listData(userId, contentIds);
        if (result.isError()) {
            throw new ServerException("[交互服务异常]异常信息:".concat(result.getMsg()));
        }
        return result.getData();
    }

    public List<UserListVO> listUser(List<Long> userIds) {
        CommonResult<List<UserListVO>> result = userFeign.listUser(userIds);
        if (result.isError()) {
            throw new ServerException("[用户服务异常]异常信息:".concat(result.getMsg()));
        }
        return result.getData();
    }

    public List<UserFollowVO> listFollowUser(Long followerUserId, List<Long> followedUserIds) {
        CommonResult<List<UserFollowVO>> result = userFeign.listUserFollow(followerUserId, followedUserIds);
        if (result.isError()) {
            throw new ServerException("[用户服务异常]异常信息:".concat(result.getMsg()));
        }
        return result.getData();
    }
}
